#include <cstdio>

int main( )
{
    int t, year, month, day, i, j, count;
    char tmp;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%c%d%c%d", &year, &tmp, &month, &tmp, &day);
        if ( month == 2 && day == 29 )
            puts("-1");
        else
        {
            count = 0;
            for ( i = year; i < year + 18; i++ )
            {
                count += 365;
                if ( ( ( i % 4 == 0 && i % 100 != 0 ) || i % 400 == 0 ) && month <= 2 )
                    count++;
                j = i + 1;
                if ( ( ( j % 4 == 0 && j % 100 != 0 ) || j % 400 == 0 ) && month > 2 )
                    count++;
            }
            printf("%d\n", count);
        }
    }
    return 0;
}
